﻿namespace D.Infrastructure.SystemRepositories
{
    public class SysUserRepository : ISysUserRepository
    {
        /// 分布式缓存
        //private readonly IDistributedCache
        //private readonly IMediator _mediator;
        //public SysUserRepository(IMediator mediator)
        //{
        //    _mediator = mediator;
        //}
        public async Task AddLoginHistoryAsync(PhoneNumberVo phoneNumberVo, string msg)
        {
            SysUserEntity? sysAdminEntity = await FindOneAsync(phoneNumberVo);
            Guid? id;
            if (sysAdminEntity != null)
            {
                id = sysAdminEntity.Id;
            }
            //SysAdminLoginHistoryEntity sysAdminLoginHistoryEntity = new SysAdminLoginHistoryEntity(id, phoneNumberVo, msg);
            // orm.Add(sysAdminLoginHistoryEntity);
        }

        public Task<SysUserEntity?> FindOneAsync(PhoneNumberVo phoneNumberVo)
        {
            return null;
        }

        public Task<SysUserEntity?> FindOneAsync(Guid sysAdminId)
        {
            return null;
        }

        public Task<string?> RetrievePhoneCodeAsync(PhoneNumberVo phoneNumberVo)
        {
            string fullNumber = phoneNumberVo.RegionCode + phoneNumberVo.PhoneNumber;
            string cacheKey = $"LoginByPhoneAndCode{fullNumber}";
            //string? code = cache.GetString(cacheKey);
            // cache.Remove(cacheKey);//验证码保存到缓存
            //return Task.FromResult(code);
            return null;
        }

        public Task SavePhoneCodeAsync(PhoneNumberVo phoneNumberVo, string code)
        {
            //string key = $"PhoneNumberCode_{phoneNumberVo.RegionCode}_{phoneNumberVo.PhoneNumber}";
            //return distributedCache.SetStringAsync(key, code, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5) });
            return null;
        }

        public Task PublishEventAsync(SysUserLoginResultEvent sysAdminLoginResultEvent)
        {
            //return _mediator.Publish(sysAdminLoginResultEvent);
            return null;
        }
    }
}
